import React, { Component } from 'react'
import FormInput from '../components/formInput'
import FormPicker from '../components/picker'
import FormCard from '../components/FormCard'
import '../assets/style/resoldhouse.less'
import axios from 'axios'
import provincial from '../Provincial.json'
//gwx  
//gwx   gwx
export default class ResoldHouse extends Component {
    constructor(props) {
        super(props)

        this.state = {
            res: [],
            colourlist: [
                { backgroundColor: '#FFEBEF', color: 'red' },
                { backgroundColor: '#E8EAF6', color: '#6978D5' },
                { backgroundColor: '#E0F7FA', color: '#51995B' },
                { backgroundColor: '#E0F8FA', color: '#579CA5' }
            ],
            sValue: [],
            priceValue: [],
            genreValue: [],
            area: '',
            price: [
                {
                    label: '1000-10000',
                    value: '1000-10000',
                },
                {
                    label: '10001-30000',
                    value: '10001-30000',
                },
                {
                    label: '30001-60000',
                    value: '10001-60000',
                },
                {
                    label: '60001-120000',
                    value: '60001-120000',
                },
                {
                    label: '120001-500000',
                    value: '120000-500000',
                },
            ],
            data1: [
                {
                    label: '厅室',
                    value: '厅室',
                },
                {
                    label: '别墅',
                    value: '别墅',
                },
                {
                    label: '小别墅',
                    value: '小别墅',
                },
            ]
        }
        this.skipdetails = this.skipdetails.bind(this)
    }
    skipdetails(e) {
        console.log(e)
    }
    async componentDidMount() {
        let res = await axios.get('/used/secondfindAll')
        console.log(res, '请求回来的数据')
        this.setState({
            res: res.data.data
        }
        )
        let citydata = provincial.Location.CountryRegion[0].State
        let regindata = []
        citydata.forEach(item => {
            let obj = {}
            obj.label = item['-Name']
            obj.value = item['-Name']
            if (item.City) {
                let children = []
                item.City.forEach(element => {
                    let obj1 = {}
                    obj1.label = element['-Name']
                    obj1.value = element['-Name']
                    if (element['Region']) {
                        let children1 = []
                        if (Array.isArray(element['Region'])) {
                            element['Region'].forEach(item1 => {
                                let obj2 = {}
                                obj2.label = item1['-Name']
                                obj2.value = item1['-Name']
                                children1.push(obj2)
                            })
                            obj1.children = children1
                        } else {
                            let obj2 = {}
                            obj2.label = element['Region']['-Name']
                            obj2.value = element['Region']['-Name']
                            children1.push(obj2)
                            obj1.children = children1
                        }
                    }
                    children.push(obj1)
                });
                obj.children = children
            }
            regindata.push(obj)
        })
        this.setState({
            area: regindata
        })
    }
    async getareaChildrenMsg(e) {
        console.log(e, '接收子传过来的区域参数')
        await this.setState({ sValue: e })
        let data = {
            area: this.state.sValue,
            price: this.state.priceValue,
            type: this.state.genreValue
        }

        let res = await axios.post('/used/secondTypeFindAll', data)
        this.setState({
            res: res.data.data
        }
        )
    }
    async getpriceChildrenMsg(e) {
        console.log(e, '接收子传过来的价格参数')
        await this.setState({ priceValue: e })
        let data = {
            area: this.state.sValue,
            price: this.state.priceValue,
            type: this.state.genreValue
        }
        let res = await axios.post('/used/secondTypeFindAll', data)

        this.setState({
            res: res.data.data
        }
        )
    }
    async getChildrenMsg(e) {
        console.log(e, '接收子传过来的类型参数')
        await this.setState({ genreValue: e })
        let data = {
            area: this.state.sValue,
            price: this.state.priceValue,
            type: this.state.genreValue
        }
        let res = await axios.post('/used/secondTypeFindAll', data)
        this.setState({
            res: res.data.data
        }
        )
    }
    render() {
        // console.log(this.state.res)
        let showCard = this.state.res.map((val, index) => {
            return (
                <FormCard key={index} href="/useddetailshouse" onClick={() => this.skipdetails(val)} data={val}></FormCard>
            )
        })
        return (
            <div className="resoldhouse">
                <FormInput></FormInput>
                <FormPicker parent={this}></FormPicker>
                {showCard}
            </div>
        )
    }
}
